﻿using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web.Mvc;
using System.IO;
using System.Data.Objects;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Linq.SqlClient;
using FilstartupsREST.Models;

namespace FilstartupsREST.FILSTARTUPSService.rest.Controllers
{
    public class PageController : Controller
    {
        //
        // GET: /Page/
        FilStartUpsEntities cms_db = new FilStartUpsEntities();



        // Take 8 First Page..
        
        [HttpGet]
        public JsonResult GetPageInfo()
        {
            var page = (from p in cms_db.Pages
                        where p.routingidFK.Equals(2)
                        select new PageNavBar
                        {
                            pageidPK = p.pageidPK,
                            pagetitle = p.pagetitle
                        }).ToList().Take(8);

            if (page.Count() > 0)
            {
                return Json(new
                {
                    data = page,
                    success = true
                }, JsonRequestBehavior.AllowGet);
            }

            else
            {
                return Json(new
                    {
                        data = string.Empty
                    }, JsonRequestBehavior.AllowGet);
            }
        }


        // up to 4

        [HttpGet]
        public JsonResult GetPageMobileInfo()
        {

            var page = (from p in cms_db.Pages
                        where p.routingidFK.Equals(2)
                        select new PageNavBar
                        {
                            pageidPK = p.pageidPK,
                            pagetitle = p.pagetitle
                        }).ToList().Take(4);

            if (page.Count() > 0)
            {
                return Json(new

                {
                    data = page,
                    success = true

                }, JsonRequestBehavior.AllowGet);

            }
            else
            {
                return Json(new { data=string.Empty }, JsonRequestBehavior.AllowGet);

            }

        }



        //skip 8 active pages()
        [HttpGet]
        public JsonResult GetPageSkip()
        {
            var skipactivepage = (from p in cms_db.Pages
                                  where p.routingidFK.Equals(2)
                                  select new PageNavBar
                                  {
                                      pageidPK = p.pageidPK,
                                      pagetitle = p.pagetitle
                                  }).OrderBy(p => p.pageidPK).Skip(8);

            if (skipactivepage.Count() > 0)
            {
                return Json(new { data = skipactivepage }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { data = string.Empty }, JsonRequestBehavior.AllowGet);
            }
        }

        // pagename - removed   
        [HttpGet]
        public JsonResult GetPageFullInfo(string id)
        {
            int pageid_ = int.Parse(id);
            var pageinfo = cms_db.Pages.Where(p => p.routingidFK == 2
                                                && p.pageidPK == pageid_
                                                ).FirstOrDefault();

            if (pageinfo != null)
            {
                return Json(new
                {
                    pageinfo,
                    success = true
                }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(
                        new
                        {
                            pageinfo = string.Empty
                        }, JsonRequestBehavior.AllowGet);
            }
        }
    }
}

